package org.dromara.learning_xq.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.learning_xq.entity.AsExaminationManagement;
import org.dromara.learning_xq.mapper.AsExaminationManagementMapper;
import org.dromara.learning_xq.service.AsExaminationManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AsExaminationManagementServiceimpl extends ServiceImpl<AsExaminationManagementMapper, AsExaminationManagement> implements AsExaminationManagementService {

    @Autowired
    private AsExaminationManagementMapper aspectExaminationManagementMapper;

    /**
     * 查询所有考试管理信息
     * <p>
     * 该方法通过调用数据库查询接口，获取系统中所有的考试管理信息
     * 由于查询条件的灵活性不高，因此直接使用list方法，并传入一个空的QueryWrapper对象以获取所有数据
     * 这种方式提高了代码的简洁性，但牺牲了一定的查询效率和灵活性
     *
     * @return 包含所有考试管理信息的列表 如果数据库中没有数据或发生错误，将返回一个空的列表
     */
    @Override
    public List<AsExaminationManagement> selectAsExaminationManagementAll() {
        return this.list(new QueryWrapper<>());
    }

    @Override
    public List<AsExaminationManagement> selectAsViewingJobsCondition(String state, String name, String subjectTeacher) {
        QueryWrapper<AsExaminationManagement> queryWrapper = new QueryWrapper<>();

        // name 模糊查询
        if (name != null && !name.isEmpty()) {
            queryWrapper.like("name", name);
        }

        // state 条件查询
        if (state != null && !state.isEmpty()) {
            queryWrapper.eq("state", state);
        }

        // subjectTeacher 条件查询
        if (subjectTeacher != null && !subjectTeacher.isEmpty()) {
            queryWrapper.eq("subject_teacher", subjectTeacher);
        }

        return aspectExaminationManagementMapper.selectList(queryWrapper);
    }
}
